import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.0

Page {
	id: page
	property var item
	property bool isRoot: false

	signal closed();
	signal itemSelected(var data);

	header: ToolBar {
		RowLayout {
			anchors.fill: parent
			Item {
				Layout.preferredWidth: 2
				visible: isRoot
			}
			ToolButton {
				visible: !isRoot
				text: "‹"
				font.pointSize: 15
				onClicked: {
					console.log("attempt to close");
					closed()
				}
			}
			Label {
				text: item.title || "Loading…"
				font.pointSize: 15
				verticalAlignment: Text.AlignVCenter
			}
		}
	}

	ColumnLayout {
		width: parent.width
		height: parent.height
		ItemView {
			item: page.item
			Layout.fillWidth: true
			Layout.fillHeight: true

			onItemSelected: {
				page.itemSelected(data);
			}
		}
	}
}
